//
//  SISSModelContractViewController.m
//  SISSAPP
//
//  Created by 优房网 on 2017/5/4.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSModelContractViewController.h"
#import "SISSModelContractWebViewController.h"

@interface SISSModelContractViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (strong, nonatomic) NSArray *titleArray;

/* 合同文本数据 */
@property (copy, nonatomic) NSArray *modelContractDataArr;

@end

@implementation SISSModelContractViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.titleArray = @[@"深圳市二手房卖方委托合同", @"深圳市二手房买方委托合同", @"房屋现状说明书", @"钥匙收条", @"交易费用预算表", @"优先购买权通知函", @"委托购买协议", @"看楼协议书", @"收据", @"深圳市二手房预约买卖及居间服务合同", @"资金监管协议", @"深圳市二手房买卖合同", @"交楼确认书", @"住宅物业家私家电清单"];
    
}


#pragma mark - UITableViewDelegate & UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   
    return self.titleArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *reuseID = @"modelContractCellResuseID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
    if ( !cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        UIView *bottomLine = [[UIView alloc] init];
        bottomLine.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell.contentView addSubview:bottomLine];
        
        [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.equalTo(cell.contentView);
            make.right.equalTo(cell.contentView).offset(64);
            make.height.mas_equalTo(1);
        }];
    }
    
    cell.textLabel.text = self.titleArray[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    SISSModelContractWebViewController *vc = [[SISSModelContractWebViewController alloc] init];
    vc.title = self.titleArray[indexPath.row];
    vc.url = self.modelContractDataArr[indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
}

- (NSArray *)modelContractDataArr {
    if (!_modelContractDataArr) {
        //获取plist
        NSURL *url = [[NSBundle mainBundle] URLForResource:@"ModelContractURLs" withExtension:@"plist"];
        
        //根据plist加载数组
        _modelContractDataArr = [NSArray arrayWithContentsOfURL:url];
    }
    return _modelContractDataArr;
}


@end
